﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MPic.Filters
{
    /// <summary>
    /// 用户拦截
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false)]
    public class UserAuthorizeAttribute : AuthorizeAttribute
    {
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            if (filterContext.HttpContext == null)
            {
                throw new ArgumentNullException("filterContext");
            }
            object[] attrs = filterContext.ActionDescriptor.GetCustomAttributes(typeof(ExcUserAuthAttribute), true);
            var isExc = attrs.Length == 1;//是否取消验证
            if (isExc)
            {
                //filterContext.Result = new HttpUnauthorizedResult();
                return;
            }
            base.OnAuthorization(filterContext);
        }
    }
}